
package com.boarsoft.boar.soagov.svc.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.common.Constants;
import com.boarsoft.boar.soagov.entity.SvcProtocol;
import com.boarsoft.boar.soagov.svc.SvcProtocolBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.util.JsonUtil;

@RestController
@RequestMapping("/svc/protocol")
public class SvcProtocolAction {
	@Autowired
	private SvcProtocolBiz svcProtocolBiz;

	/**
	 * 查询服务支持的协议关系列表
	 * 
	 * @return
	 */
	@RequestMapping("/list.do")
	@Authorized(code = "svc.protocol.list")
	public ReplyInfo<String> list(String svcId) {
		List<SvcProtocol> lt = svcProtocolBiz.list(svcId);
		return new ReplyInfo<String>(true, JsonUtil.from(lt));
	}

	/**
	 * 保存服务和协议的关系
	 * 
	 * @return
	 */
	@RequestMapping("/saveList.do")
	@Authorized(code = "svc.protocol.saveList")
	public ReplyInfo<Object> saveList(String svcIds, String protocolIds, boolean flag) {
		if (svcProtocolBiz.save(protocolIds.split(","), svcIds.split(","), flag)) {
			return ReplyInfo.SUCCESS;
		}
		return ReplyInfo.FAILED;
	}

	/**
	 * 保存服务和协议的关系
	 * 
	 * @return
	 */
	@RequestMapping("/save.do")
	@Authorized(code = "svc.protocol.save")
	public ReplyInfo<Object> save(SvcProtocol o) {
		if (svcProtocolBiz.save(o)) {
			return ReplyInfo.SUCCESS;
		}
		return Constants.REPLY_WARN_INVALID;
	}

	@RequestMapping("/delete.do")
	@Authorized(code = "svc.protocol.delete")
	public ReplyInfo<Object> delete(String svcId, String protocolId) {
		svcProtocolBiz.delete(svcId, protocolId);
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/remove.do")
	@Authorized(code = "svc.protocol.remove")
	public ReplyInfo<Object> remove(String svcIds) {
		svcProtocolBiz.delete(svcIds.split(","));
		return ReplyInfo.SUCCESS;
	}
}